import {Component, HostListener} from '@angular/core';

@Component({
    selector: 'app-root',
    template: `
        {{param}}
        <button (click)="test()">test</button>
    `,
    styles: []
})
export class AppComponent {
    param = 'init'

    test() {
        console.log(111)
    }

    ngOnInit() {
        (global as any).myWin = nw.Window.get()
    }

    @HostListener('document:contextmenu', ['$event'])
    clickEvent($event: PointerEvent) {
        $event.preventDefault();
        let win = nw.Window.get();
        let menu = new nw.Menu();
        let submenu1 = new nw.MenuItem({
            label: '最小化', click: () => {
                win.minimize()
            }
        });
        let submenu2 = new nw.MenuItem({
            label: '最大化', click: () => {
                win.maximize()
            }
        });
        let submenu3 = new nw.MenuItem({
            label: '还原', click: () => {
                win.restore()
            }
        });
        menu.append(submenu1)
        menu.append(submenu2)
        menu.append(submenu3)
        menu.popup($event.clientX, $event.clientY)
    }
}
